/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cloud.pole.weixin.wechat.message;

import java.util.List;

public class TemplateMsg {
    private String openId;
    private String templateId;
    private String url;
    private String topcolor;
    private List<TemplateData> templateData;
    
    public void setOpenId(String openId){this.openId = openId;}
    public String getOpenId(){return openId;}
    
    public void setTemplateId(String templateId){this.templateId = templateId;}
    public String getTemplateId(){return templateId;}
    
    public void setUrl(String url){this.url = url;}
    public String getUrl(){return url;}
    
    public void setTopcolor(String topcolor){this.topcolor=topcolor;}
    public String getTopcolor(){return topcolor;}
    
    public void setTemplateData(List<TemplateData> templateData){this.templateData = templateData;}
    public List<TemplateData> getTemplateData(){return templateData;}
    
    public String toJosnString(){
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        sb.append("\"touser\":\"").append(openId).append("\",");
        sb.append("\"template_id\":\"").append(templateId).append("\",");
        sb.append("\"url\":\"").append(url).append("\",");
        sb.append("\"topcolor\":\"").append(topcolor).append("\",");
        sb.append("\"data\":{");
        if(templateData.size()>0){
            for(int i=0;i<templateData.size();i++){
                TemplateData data = templateData.get(i);
                sb.append("\"").append(data.getName()).append("\":{");
                sb.append("\"value\":\"").append(data.getValue()).append("\",");
                sb.append("\"color\":\"").append(data.getColor()).append("\"");
                sb.append("}");
                if(i!=(templateData.size()-1)){
                    sb.append(",");
                }
            }
        }
        sb.append("}");
        sb.append("}");
        return sb.toString();
    }
}
